﻿using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using SlamDunk.CMS.Model.DataModel;

namespace SlamDunk.CMS.Model.ViewModel
{
    /// <summary>
    /// Menus视图模型类
    /// </summary>
    public class MenusView
    {
        #region 01.属性——Id
        /// <summary>
        /// 属性——Id
        /// </summary>
        public int Id { get; set; }
        #endregion

        #region 02.属性——父Id
        /// <summary>
        /// 属性——父Id
        /// </summary>
        [Required(ErrorMessage = "必填")]
        [RegularExpression(@"\d{1,2}", ErrorMessage = "必须是数字")]
        [DisplayName("上级菜单")]
        public int PId { get; set; }
        #endregion

        #region 03.属性——菜单名称
        /// <summary>
        /// 属性——菜单名称
        /// </summary>
        [Required(ErrorMessage = "必填")]
        [StringLength(16, ErrorMessage = "名称过长")]
        [DisplayName("菜单名称")]
        public string MenuName { get; set; }
        #endregion

        #region 04.属性——链接地址
        /// <summary>
        /// 属性——链接地址
        /// </summary>
        [StringLength(256, ErrorMessage = "名称过长")]
        [DisplayName("链接地址")]
        public string Url { get; set; }
        #endregion

        #region 05.属性——是否是链接
        /// <summary>
        /// 属性——是否是链接
        /// </summary>
        [Required(ErrorMessage = "必填")]
        [DisplayName("是否是链接")]
        public bool? IsLink { get; set; }
        #endregion

        #region 06.属性——菜单等级
        /// <summary>
        /// 属性——菜单等级
        /// </summary>
        [Required(ErrorMessage = "必填")]
        [RegularExpression(@"\d{1,2}", ErrorMessage = "必须是数字")]
        [Range(0, 10, ErrorMessage = "数字过大")]
        [DisplayName("菜单等级")]
        public int Level { get; set; }
        #endregion

        #region 07.属性——排序
        /// <summary>
        /// 属性——排序
        /// </summary>
        [Required(ErrorMessage = "必填")]
        [RegularExpression(@"\d+", ErrorMessage = "必须是数字")]
        [Range(0, 100000, ErrorMessage = "数字过大")]
        [DisplayName("排序")]
        public int? Sort { get; set; }
        #endregion

        #region 08.属性——图标
        /// <summary>
        /// 属性——图标
        /// </summary>
        [StringLength(256, ErrorMessage = "内容过长")]
        [DisplayName("图标")]
        public string Ico { get; set; }
        #endregion

        #region 09.方法——转换为数据模型
        /// <summary>
        /// 转换为数据模型
        /// </summary>
        /// <returns>Menus数据模型对象</returns>
        public Menus ToDataModel()
        {
            return new Menus()
            {
                Id = this.Id,
                PId = this.PId,
                MenuName = this.MenuName,
                Url = this.Url,
                IsLink = this.IsLink,
                Level = this.Level,
                Sort = this.Sort,
                Ico = this.Ico,
                DelFlag = false,
                AddTime = DateTime.Now
            };
        }
        #endregion
    }
}
